<template>
  <!-- hidden PageHeaderWrapper title demo -->
  <page-header-wrapper :title="false" >
    <a-card :body-style="{padding: '24px 32px'}" :bordered="false">
      <a-alert message="合并时将供应商1合并至供应商2，合并之后，供应商1消失。请谨慎操作，该操作不可恢复。" type="error" />
      <a-form @submit="handleSubmit" :form="form">
        <a-form-item
          label="供应商1"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-select v-decorator="['supply1']" placeholder="请选择供应商" >
            <a-select-option :value="i.id" v-for="i in supplyoption" :key="i.id">{{ i.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="供应商2"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-select v-decorator="['supply2']" placeholder="请选择供应商" >
            <a-select-option :value="i.id" v-for="i in supplyoption" :key="i.id">{{ i.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          :wrapperCol="{ span: 24 }"
          style="text-align: center"
        >
          <a-button htmlType="submit" type="primary" icon="check">提交</a-button>
          <!-- <a-button style="margin-left: 8px">{{ $t('form.basic-form.form.save') }}</a-button> -->
        </a-form-item>
      </a-form>
    </a-card>
  </page-header-wrapper>
</template>
  
<script>
  import { mergeSuppliesUsingPOST,getSuppliesListUsingPOST } from '@/api/api/jingxiaoshangyunyingshangguanli.ts'
  export default {
    name: 'ReturnFactoryOutStoreIndex',
    data () {
      return {
        supplyoption:[],
        optionParam: {
        pageNo:1,
        pageSize:9999,
        queryCondition:'',
      },
        form: this.$form.createForm(this)
      }
    },
    mounted() {
    this.getSupOption()
  },
    methods: {
      // handler
    getSupOption() {
      getSuppliesListUsingPOST({...this.optionParam,}).then((res) => {
          this.supplyoption = res.data.list
        }).catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleSubmit (e) {
        e.preventDefault()
        this.form.validateFields((err, values) => {
          if (!err) {
            mergeSuppliesUsingPOST({...values}).then((res) => { 
              this.$message.success('操作成功')
              // 重置表单数据
              this.form.resetFields()
            }).catch((error) => {
              console.log(error)
              this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
            })
          }
        })
      }
    }
  }
</script>